home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume11 / soundslike < prev    next >
Encoding:
Internet Message Format  |  1987-10-18  |  7.5 KB

  1. Return-Path: @UUNET.UU.NET:sun!pyramid!prls!gordon@seismo.CSS.GOV
  2. Message-Id: <8710010021.AA10975@pyramid.UUCP>
  3. Date: Wed, 30 Sep 87 16:51:45 pdt
  4. From: Gordon Vickers <sun!prls!gordon@seismo.CSS.GOV>
  5. To: sources@seismo.CSS.GOV
  6. Subject: soundslike; LOOK(1) like program with soundex
  7.  
  8. This is another aid to those who can't spell .  It is similar to the basic
  9. function of LOOK(1) but uses what I believe is the "soundex" algorithm.
  10. The code is VERY tame so I would expect to to port easily though I am no
  11. expert on such matters.  Comments, suggestions, etc are welcomed.
  12.  
  13.  
  14. Gordon P. Vickers, (408) 991-5370,             =======================
  15. Signetics Corp.                                || Ultrix-32 ver 1.2 ||
  16. PO Box 3409  M/S 69                            ||     VAX 11/750    ||
  17. Sunnyvale, California,  USA  94086             =======================
  18. {pyramid, philabs}!prls!gordon
  19.  
  20. [  I turned the formatted manpage into an unformatted one, along with
  21.    light editing, and wrote a Makefile.  Feel free to take the latter
  22.    as a prototype makefile for submissions...  Also, I don't know if
  23.    this is true "soundex" or not -- and I don't care -- it works nicely.
  24.    --r$  ]
  25.  
  26. #! /bin/sh
  27. # This is a shell archive.  Remove anything before this line, then unpack
  28. # it by saving it into a file and typing "sh file".  To overwrite existing
  29. # files, type "sh file -c".  You can also feed this as standard input via
  30. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  31. # will see the following message at the end:
  32. #        "End of shell archive."
  33. # Contents:  Makefile soundslike.1 soundslike.c
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'Makefile'\"
  37. else
  38. echo shar: Extracting \"'Makefile'\" \(178 characters\)
  39. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  40. X# Makefile for soundslike.
  41. XCFLAGS    = -O
  42. Xp    = soundslike
  43. Xall:        $p $p.1
  44. Xinstall:    all
  45. X    @echo install $p and $p.1 according to local convention.
  46. X
  47. X$p:        $p.c
  48. X    $(CC) $(CFLAGS) -o $p $p.c
  49. END_OF_FILE
  50. if test 178 -ne `wc -c <'Makefile'`; then
  51.     echo shar: \"'Makefile'\" unpacked with wrong size!
  52. fi
  53. # end of 'Makefile'
  54. fi
  55. if test -f 'soundslike.1' -a "${1}" != "-c" ; then 
  56.   echo shar: Will not clobber existing file \"'soundslike.1'\"
  57. else
  58. echo shar: Extracting \"'soundslike.1'\" \(928 characters\)
  59. sed "s/^X//" >'soundslike.1' <<'END_OF_FILE'
  60. X.TH SOUNDSLIKE 1 LOCAL
  61. X.SH NAME
  62. Xsoundslike \- spell word based on what it sounds like
  63. X.SH SYNOPSIS
  64. X.B soundslike
  65. Xword
  66. X.br
  67. X.B soundslike
  68. X-filename word
  69. X.br
  70. X.B soundslike
  71. Xword -filename
  72. X.SH DESCRIPTION
  73. X.I Soundslike
  74. Xuses an implementation of the soundex algorithm.
  75. XType the word in question as best as you can,
  76. Xand the program will search a database for similar-sounding words.
  77. XThe default database is normally
  78. X.I /usr/dict/words
  79. Xbut the user may specify any other file.
  80. X.PP
  81. XRegardless of which file is specified as the database, only the
  82. Xfirst word of each line is tested against the users' word.
  83. X.PP
  84. XFor example,
  85. X.RS
  86. Xsoundslike butiful
  87. X.RE
  88. Xwill produce:
  89. X.RS
  90. Xbeautiful
  91. Xbiddable
  92. Xbotfly
  93. X.RE
  94. Xand
  95. X.RS
  96. Xsoundslike nessaccary 
  97. X.RE
  98. Xproduces:
  99. X.RS
  100. Xnecessary
  101. X.RE
  102. X.SH RESTRICTIONS
  103. XYou must be able to at least get the first letter correct.
  104. X.SH AUTHOR
  105. X.nf
  106. XGordon P. Vickers
  107. XSignetics Corp. , Sunnyvale, Ca.
  108. X{pyramid, philabs}!prls!gordon
  109. X.fi
  110. END_OF_FILE
  111. if test 928 -ne `wc -c <'soundslike.1'`; then
  112.     echo shar: \"'soundslike.1'\" unpacked with wrong size!
  113. fi
  114. # end of 'soundslike.1'
  115. fi
  116. if test -f 'soundslike.c' -a "${1}" != "-c" ; then 
  117.   echo shar: Will not clobber existing file \"'soundslike.c'\"
  118. else
  119. echo shar: Extracting \"'soundslike.c'\" \(3557 characters\)
  120. sed "s/^X//" >'soundslike.c' <<'END_OF_FILE'
  121. X#include <stdio.h>
  122. X#include <strings.h>
  123. X
  124. X/*******************************************************
  125. X *  Soundex (like) filter.  Default database is DEFDB  *
  126. X *     or user specifies with "-filename"              *
  127. X *     syntex: soundex word                            *
  128. X *             soundex -database word                  *
  129. X *             soundex word -database                  *
  130. X ******************************************************/
  131. X
  132. X#define DEFDB  "/usr/dict/words"   /* default database  */
  133. X
  134. Xmain(argc,argv)
  135. X  int    argc;
  136. X  char **argv;
  137. X{
  138. X   void mkcode(), syntex();
  139. X   int i;
  140. X   char c;
  141. X   char dbname[BUFSIZ], word[BUFSIZ], s[BUFSIZ];
  142. X   char dbword[BUFSIZ], dbcode[BUFSIZ];
  143. X
  144. X   sprintf(dbname,"%s",DEFDB);
  145. X   if(argc == 1) 
  146. X      syntex(argv[0]);  /* print syntex help then exit */
  147. X   
  148. X
  149. X   for(i = 1; argv[i] != NULL; i++) {   /* process argument line */
  150. X     if( argv[i][0] == '-')
  151. X        sprintf(dbname,"%s",argv[i]);
  152. X     else
  153. X        sprintf(word,"%s",argv[i]);
  154. X   }
  155. X
  156. X   if( !strlen(word) )
  157. X        syntex(argv[0]);
  158. X
  159. X   if ( freopen(dbname,"r",stdin) == NULL ) {
  160. X      perror(dbname);
  161. X      exit(0);
  162. X   }
  163. X
  164. X   /*  Sanity checks done.  Now, down to buisness */
  165. X
  166. X   c = word[0]; 
  167. X   mkcode(word);
  168. X
  169. X   while( (gets(dbword) ) != NULL ) {
  170. X       if( c < dbword[0] )    /* assumes database is in alphabetical order */
  171. X           break;
  172. X       else if (c > dbword[0])
  173. X           continue;
  174. X       else {
  175. X          sscanf(dbword,"%s%*s",dbcode); /* isolate only first word     */
  176. X          sprintf(dbword,"%s",dbcode);   /* truncate dbword to one word */
  177. X          mkcode(dbcode);                /* convert to code             */
  178. X           if( !strcmp(dbcode,word) )    /* check for exact code match  */
  179. X             printf("%s\n",dbword);
  180. X       }
  181. X   }
  182. X}
  183. X
  184. X/*********************************   MKCODE()  ****************************/
  185. Xvoid mkcode(codeword)
  186. X   char  *codeword;
  187. X{
  188. X    int i, j = 0;
  189. X    int l;
  190. X
  191. X    l = strlen(codeword);
  192. X    if(l <= 1){           /* this should probably return some snide remark */
  193. X        codeword[l] = '\0';
  194. X        return;
  195. X    }
  196. X
  197. X    for(i = 1; codeword[i] != NULL; i++) {
  198. X         if(codeword[i] == codeword[i - 1])
  199. X             continue;
  200. X         switch (codeword[i]) {
  201. X             case 'b':
  202. X             case 'f':
  203. X             case 'p':
  204. X             case 'v': codeword[j] = '1';
  205. X                       j++;
  206. X                       break;
  207. X
  208. X             case 'c':
  209. X             case 'g':
  210. X             case 'j':
  211. X             case 'k':
  212. X             case 'q':
  213. X             case 's':
  214. X             case 'x':
  215. X             case 'z': codeword[j] = '2';
  216. X                       j++;
  217. X                       break;
  218. X
  219. X             case 'd':
  220. X             case 't':  codeword[j] = '3';
  221. X                        j++;
  222. X                        break;
  223. X
  224. X             case 'l':  codeword[j] = '4';
  225. X                        j++;
  226. X                        break;
  227. X
  228. X             case 'm':
  229. X             case 'n':  codeword[j] = '5';
  230. X                        j++;
  231. X                        break;
  232. X
  233. X             case 'r':  codeword[j] = '6';
  234. X                        j++;
  235. X                        break;
  236. X
  237. X             default :  break;
  238. X        }
  239. X     }
  240. X     codeword[j] = '\0';
  241. X     while( strlen(codeword) < 3 )  /* pad with zeroes til minimum length */
  242. X        strcat(codeword,"0");
  243. X
  244. X
  245. X}
  246. X
  247. X/*******************************   SYNTEX()   **************************/
  248. Xvoid syntex(name)
  249. X  char *name;
  250. X{
  251. X     printf("syntex:  %s word\n",name);
  252. X     printf("    or   %s -database word\n",name);
  253. X     printf("     or  %s word -database\n",name);
  254. X     exit(0);
  255. X}
  256. END_OF_FILE
  257. if test 3557 -ne `wc -c <'soundslike.c'`; then
  258.     echo shar: \"'soundslike.c'\" unpacked with wrong size!
  259. fi
  260. # end of 'soundslike.c'
  261. fi
  262. echo shar: End of shell archive.
  263. exit 0
  264.